//
//  GuideViewController.m
//  礼物go
//
//  Created by dllo on 16/6/2.
//  Copyright © 2016年 dllo. All rights reserved.
//

#import "GuideViewController.h"

@interface GuideViewController ()<UIScrollViewDelegate>

@property(nonatomic,strong)UIPageControl *mypage;
@property(nonatomic,strong)UIScrollView *myScorollView;

@end

@implementation GuideViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    
    [self initGuide];
    
    
    // Do any additional setup after loading the view.
}

-(void)initGuide{
    
    self.myScorollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH , SCREENHeight)];
    [self.myScorollView setContentSize:CGSizeMake(SCREENWIDTH * 4, 0)];
    [self.myScorollView setPagingEnabled:YES];  //视图整页显示
    [self.myScorollView setBounces:NO]; //避免弹跳效果,避免把根视图露出来
    //按页滑动
    self.myScorollView.pagingEnabled = YES;
    //隐藏滚动条(水平)
    self.myScorollView.showsHorizontalScrollIndicator = NO;
    self.myScorollView.delegate = self;
    
    UIImageView *imageview = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, SCREENWIDTH, SCREENHeight)];
    [imageview setImage:[UIImage imageNamed:@"walkthrough_1.jpg"]];
    [self.myScorollView addSubview:imageview];
    
    UIImageView *imageview1 = [[UIImageView alloc] initWithFrame:CGRectMake(SCREENWIDTH, 0, SCREENWIDTH, SCREENHeight)];
    [imageview1 setImage:[UIImage imageNamed:@"walkthrough_2.jpg"]];
    [self.myScorollView addSubview:imageview1];
    
    
    UIImageView *imageview2 = [[UIImageView alloc] initWithFrame:CGRectMake(SCREENWIDTH * 2, 0, SCREENWIDTH, SCREENHeight)];
    [imageview2 setImage:[UIImage imageNamed:@"walkthrough_3.jpg"]];
    [self.myScorollView addSubview:imageview2];
    
    
    UIImageView *imageview3 = [[UIImageView alloc] initWithFrame:CGRectMake(SCREENWIDTH * 3, 0, SCREENWIDTH, SCREENHeight)];
    [imageview3 setImage:[UIImage imageNamed:@"walkthrough_4.jpg"]];
    imageview3.userInteractionEnabled = YES;    //打开imageview3的用户交互;否则下面的button无法响应
    [self.myScorollView addSubview:imageview3];
    

    [self.view addSubview:self.myScorollView];
    
    
    //  imageView 点击事件
    UITapGestureRecognizer *gest = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(GestAction:)];
    imageview3.userInteractionEnabled = YES;
    [imageview3 addGestureRecognizer:gest];
    
    
    
    
    
    self.mypage = [[UIPageControl alloc]initWithFrame:CGRectMake(107, 700, 200, 30)];
    self.mypage.backgroundColor = [UIColor clearColor];
    [self.view addSubview:self.mypage];
    
    //点的个数
    self.mypage.numberOfPages = 4;
    self.mypage.alpha = 0.3;//修改透明度
    self.mypage.layer.masksToBounds = YES;//修改弧度
    self.mypage.layer.cornerRadius = 10;
    [self.mypage addTarget:self action:@selector(pageAction:) forControlEvents:UIControlEventValueChanged];
    
    
}

-(void)pageAction:(UIPageControl *)page{
    
    [self.myScorollView setContentOffset:CGPointMake(SCREENWIDTH * page.currentPage, 0) animated:YES];
}


-(void)scrollViewDidEndDecelerating:(UIScrollView *)scrollView{
    
    self.mypage.currentPage = scrollView.contentOffset.x / SCREENWIDTH;
    //currentpage  当前页          contenoffset 偏移量
    
    for (UIScrollView *mall in scrollView.subviews) {
        //判断mall是不是UIScrollView类型的视图
        if ([mall isKindOfClass:[UIScrollView class]]) {
            mall.zoomScale = 1.0;
        }
    }
    
}

-(void)GestAction:(UIGestureRecognizerState *)gest{
    
    self.backToMainVC();
    
    //NSLog(@"进入主页");
}




- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
